﻿using Enterprise_Get.API.Application.Commands.BasicInformations;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Enterprise_Get.API.Controllers.Week1
{
    /// <summary>
    /// 第一周基础信息显示
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BasisController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        public IMediator mediator { get; set; }
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<BasisController> logger;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        /// <param name="logger"></param>
        public BasisController(IMediator mediator, ILogger<BasisController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 企业显示查询分页
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<THE_WIND_RISES.Common.Dtos.Result> QueryEnterprise(EnterpriseQueryCommand cmd)
        {
            try
            {
                logger.LogInformation("企业显示查询分页");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("企业显示查询分页失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 部门显示查询分页
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<THE_WIND_RISES.Common.Dtos.Result> QueryDepartment(DepartmentQueryCommand cmd)
        {
            try
            {
                logger.LogInformation("部门显示查询分页");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("部门显示查询分页失败" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 企业显示
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<THE_WIND_RISES.Common.Dtos.Result> ShowEnterprise(EnterpriseShowCommand cmd)
        {
            try
            {
                logger.LogInformation("企业显示");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("企业显示失败" + ex.Message);
                throw;
            }
        }


    }
}
